import 'package:dio/dio.dart';
import 'package:schedule_self_client/api/user_center/login_resp.dart';
import 'package:schedule_self_client/api/user_center/user_info_qry_resp.dart';
import 'package:schedule_self_client/common/api_common.dart';
import 'package:schedule_self_client/common/simple_resp.dart';

class UserApi {
  static final Dio _dio = Dio(BaseOptions(
    baseUrl: ApiCommon.baseUrl,
    headers: {},
  ));

  static init(InterceptorsWrapper interceptorsWrapper) {
    _dio.interceptors.add(interceptorsWrapper);
  }

  static Future<LoginResp?> login(
      String username, String password, int? verifyCode) async {
    Response response = await _dio.post('/user/v1/login',
        options: Options(contentType: "application/json"),
        data: {
          'username': username,
          'password': password,
          'verifyCode': verifyCode
        });
    return LoginResp.fromJson(response.data);
  }

  static Future<UserInfoQryResp> queryUserInfo() async {
    Response response = await _dio.get('/user/v1/getUserInfo');
    return UserInfoQryResp.fromJson(response.data);
  }

  static Future<SimpleResp> logout() async {
    Response response = await _dio.get('/user/v1/logout');
    return SimpleResp.fromJson(response.data);
  }
}
